package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GxClinic;
import com.ruoyi.system.service.IGxClinicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 就诊信息Controller
 * 
 * @author gx
 * @date 2022-05-07
 */
@RestController
@RequestMapping("/system/clinic")
public class GxClinicController extends BaseController
{
    @Autowired
    private IGxClinicService gxClinicService;

    /**
     * 查询就诊信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:clinic:list')")
    @GetMapping("/list")
    public TableDataInfo list(GxClinic gxClinic)
    {
        startPage();
        List<GxClinic> list = gxClinicService.selectGxClinicList(gxClinic);
        return getDataTable(list);
    }


    /**
     * 查询每个人最近一次的就诊信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:clinic:list')")
    @GetMapping("/listbyone")
    public TableDataInfo listbyone(GxClinic gxClinic)
    {
        startPage();
        List<GxClinic> list = gxClinicService.selectGxClinicListbyone(gxClinic);
        return getDataTable(list);
    }

    /**
     * 查询住院患者的就诊信息
     */
//    @PreAuthorize("@ss.hasPermi('system:clinic:list')")
    @GetMapping("/alive")
    public TableDataInfo clinicIdAlive(GxClinic gxClinic)
    {
        startPage();
        List<GxClinic> list = gxClinicService.selectGxClinicByClinicIdAlive(gxClinic);
        return getDataTable(list);
    }

    /**
     * 导出就诊信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:clinic:export')")
    @Log(title = "就诊信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxClinic gxClinic)
    {
        List<GxClinic> list = gxClinicService.selectGxClinicList(gxClinic);
        ExcelUtil<GxClinic> util = new ExcelUtil<GxClinic>(GxClinic.class);
        util.exportExcel(response, list, "就诊信息数据");
    }

    /**
     * 获取就诊信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:clinic:query')")
    @GetMapping(value = "/{clinicId}")
    public AjaxResult getInfo(@PathVariable("clinicId") Long clinicId)
    {
        return AjaxResult.success(gxClinicService.selectGxClinicByClinicId(clinicId));
    }

    /**
     * 新增就诊信息
     */
//    @PreAuthorize("@ss.hasPermi('system:clinic:add')")
    @Log(title = "就诊信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxClinic gxClinic)
    {
        return toAjax(gxClinicService.insertGxClinic(gxClinic));
    }

    /**
     * 修改就诊信息
     */
//    @PreAuthorize("@ss.hasPermi('system:clinic:edit')")
    @Log(title = "就诊信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxClinic gxClinic)
    {
        return toAjax(gxClinicService.updateGxClinic(gxClinic));
    }

    /**
     * 删除就诊信息
     */
//    @PreAuthorize("@ss.hasPermi('system:clinic:remove')")
    @Log(title = "就诊信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clinicIds}")
    public AjaxResult remove(@PathVariable Long[] clinicIds)
    {
        return toAjax(gxClinicService.deleteGxClinicByClinicIds(clinicIds));
    }
}
